﻿// See https://aka.ms/new-console-template for more information
using Config1;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System.Data.SqlClient;

ConfigurationBuilder builder = new ConfigurationBuilder();

string cs = "Server=127.0.0.1;Database=test;Trusted_Connection=true;";
builder.AddDbConfiguration(() => new SqlConnection(cs), reloadOnChange: true,
    reloadInterval: TimeSpan.FromSeconds(2));


IConfigurationRoot configRoot =builder.Build();

ServiceCollection serviceCollection = new ServiceCollection();
serviceCollection.AddScoped<TestController>();

//可以链式配置
serviceCollection
    .Configure<Config>(a => configRoot.Bind(a))
    .Configure<Proxy>(a => configRoot.GetSection("proxy").Bind(a));


using (ServiceProvider sp = serviceCollection.BuildServiceProvider())
{
    var c=sp.GetRequiredService<TestController>();
    c.Test();
}

Console.ReadKey();








